package com.bingxue.edu.parent.controller;

import com.bingxue.edu.common.enums.EmployeeTypeEnum;
import com.bingxue.edu.framework.common.model.Response;
import com.bingxue.edu.framework.mybatis.query.QueryBuilder;
import com.bingxue.edu.management.education.model.query.ArrangeTemplateQuery;
import com.bingxue.edu.management.education.model.resp.ArrangeTemplateResp;
import com.bingxue.edu.management.education.model.resp.TimeTemplateResp;
import com.bingxue.edu.management.education.service.ArrangeTemplateService;
import com.bingxue.edu.management.education.service.TimeTemplateService;
import com.bingxue.edu.management.system.model.query.EmployeeQuery;
import com.bingxue.edu.management.system.service.EmployeeService;
import com.bingxue.edu.parent.model.entity.ParentTeacherInfo;
import com.mybatisflex.core.query.QueryWrapper;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static com.bingxue.edu.management.education.model.entity.table.TimeTemplateTableDef.TIME_TEMPLATE;

@RestController
@RequestMapping("/p/common")
@RequiredArgsConstructor
public class ParentCommonController {

    private final ArrangeTemplateService arrangeTemplateService;
    private final TimeTemplateService timeTemplateService;
    private final EmployeeService employeeService;

    @Operation(summary ="查询期段列表")
    @GetMapping("/arrange-template/list")
    public Response<List<ArrangeTemplateResp>> listArrangeTemplate(@Validated ArrangeTemplateQuery query){
        QueryWrapper queryWrapper = QueryBuilder.build(query);
        List<ArrangeTemplateResp> list = arrangeTemplateService.listAs(queryWrapper, ArrangeTemplateResp.class);
        return Response.success(list);
    }

    @Operation(summary ="查询时间段列表")
    @GetMapping("/time-template/list")
    public Response<List<TimeTemplateResp>> listTimeTemplate(){
        QueryWrapper queryWrapper = QueryWrapper.create().orderBy(TIME_TEMPLATE.START_TIME, true);
        List<TimeTemplateResp> result = timeTemplateService.listAs(queryWrapper, TimeTemplateResp.class);
        return Response.success(result);
    }

    @Operation(summary ="查询老师列表")
    @GetMapping("/teacher/list")
    public Response<List<ParentTeacherInfo>> listTeacher(EmployeeQuery query) {
        query.setType(EmployeeTypeEnum.LEAD_TEACHER);
        QueryWrapper queryWrapper = QueryBuilder.build(query);
        List<ParentTeacherInfo> list = employeeService.listAs(queryWrapper, ParentTeacherInfo.class);
        return Response.success(list);
    }
}
